package net.hn.hnms.biz.energy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.hn.hnms.biz.energy.domain.ElectricitySettlement;
import net.hn.hnms.biz.energy.vo.ElectricitySettlementVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface ElectricitySettlementMapper extends BaseMapper<ElectricitySettlement> {
    @Update("<script>" +
            " update  electricity_settlement set  del_flag = '1' " +
            " where electricity_settle_id in" +
            " <foreach collection=\"list\" item=\"value\" separator=\",\" open=\"(\" close=\")\">\n" +
            "#{value}" +
            "</foreach>" +
            "</script>")
    void updateDeleteByIds(@Param("list") List<String> list);

    @Select("<script>" +
            "SELECT SUM\n" +
            "\t( magnification ) AS electricalLoadCount,\n" +
            "\tSUM ( settle_electric_consumption ) AS settleElectricConsumptionCount,\n" +
            "\tSUM ( settle_electric_amount ) AS settleElectricAmountCount \n" +
            "FROM\n" +
            "\telectricity_settlement \n" +
            "WHERE\n" +
            "\tmine_code = #{mineCode} \n" +
            "\tAND del_flag = '0'</script>")
    ElectricitySettlementVo getElectricitySettlementByMineCode(@Param("mineCode")String mineCode);


    @Select("<script>" +
            "SELECT " +
            "electricity_place_name,electricity_place_id," +
            "SUM ( settle_electric_consumption ) AS settleElectricConsumptionCount " +
            "FROM " +
            "electricity_settlement " +
            "WHERE " +
            "del_flag = '0' " +
            "AND settle_date <![CDATA[ >= ]]> to_date( #{beginDate}, 'YYYY-MM-DD') " +
            "AND settle_date <![CDATA[ <= ]]> to_date( #{endDate}, 'YYYY-MM-DD') " +
            "<if test='mineCode != null and mineCode != \"\" '> " +
            "and mine_code = #{mineCode} " +
            "</if>" +
            "GROUP BY " +
            "electricity_place_name,electricity_place_id" +
            "</script>")
    List<ElectricitySettlementVo> getEachTeamKwh(@Param("mineCode")String mineCode, @Param("beginDate") Date beginDate, @Param("endDate")Date endDate);

//    @InterceptorIgnore(tenantLine = "true")
    @Select("<script>SELECT " +
            "to_char( settle_date, 'yyyy-mm' ) AS countDate ," +
            "SUM ( settle_electric_consumption ) AS settleElectricConsumptionCount " +
            "FROM " +
            "electricity_settlement " +
            "WHERE " +

            "del_flag='0' " +
            "AND settle_date <![CDATA[ >= ]]> to_date( #{beginDate}, 'YYYY-MM-DD') " +
            "AND settle_date <![CDATA[ <= ]]> to_date( #{endDate}, 'YYYY-MM-DD') " +
            " <if test='mineCode != null and mineCode != \"\" '> " +
            " and mine_code = #{mineCode} " +
            " </if> " +
            " and electricity_place_id=#{electricityPlaceId} " +
            "GROUP BY " +
            " to_char( settle_date, 'yyyy-mm' ) " +
            "</script>")
    List<ElectricitySettlementVo> getEachYearKwh(@Param("mineCode")String mineCode,@Param("beginDate")Date beginDate,@Param("endDate")Date endDate, @Param("electricityPlaceId")String electricityPlaceId);






}
